﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class manage_Default2 : System.Web.UI.Page
{
    protected clsAdvertisement Advertisement;
    protected void Page_Load(object sender, EventArgs e)
    {
        Advertisement = new clsAdvertisement();
        if (!IsPostBack)
        {
            FillGrid();
        }
    }
    public void FillGrid()
    {
        DataTable lstaccount = Advertisement.getTableAdv();
        if (lstaccount.Rows.Count > 0)
        {
            grdUser.DataSource = lstaccount;
            grdUser.DataBind();
        }
        else
        {
            lstaccount.Rows.Add(lstaccount.NewRow());
            grdUser.DataSource = lstaccount;
            grdUser.DataBind();
            int TotalColumns = grdUser.Rows[0].Cells.Count;
            grdUser.Rows[0].Cells.Clear();
            grdUser.Rows[0].Cells.Add(new TableCell());
            grdUser.Rows[0].Cells[0].ColumnSpan = TotalColumns;
            grdUser.Rows[0].Cells[0].Text = "Không tồn tại thông tin quảng cáo nào";
        }
    }
    protected void grdUser_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grdUser.PageIndex = e.NewPageIndex;
        FillGrid();
    }
    protected void grdUser_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("Xoá"))
        {
            int id = Convert.ToInt32(e.CommandArgument);
            Advertisement.Id = id;
            //Advertisement.DeleteAccount();
            FillGrid();
        }
        else if (e.CommandName.Equals("Active"))
        {
            int id = Convert.ToInt32(e.CommandArgument);
            Advertisement.Id = id;
            Advertisement.active_unactive();
            FillGrid();
        }
    }

}
